package com.mine.service.impl;

import com.mine.common.pojo.EasyUITreeNode;
import com.mine.mapper.TbItemCatMapper;
import com.mine.pojo.TbItemCat;
import com.mine.pojo.TbItemCatExample;
import com.mine.service.ItemCatService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ItemCatServiceImpl implements ItemCatService {
    @Resource
    TbItemCatMapper itemMapper;
    @Override
    public  List<EasyUITreeNode>  getItemCatList(long parentId) {
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        List<TbItemCat> tbItemCats = itemMapper.selectByExample(example);
        List<EasyUITreeNode> result = new ArrayList<>();
        for (TbItemCat tbItemCat : tbItemCats) {
            EasyUITreeNode node = new EasyUITreeNode();
            node.setId(tbItemCat.getId());
            node.setText(tbItemCat.getName());
            node.setState(tbItemCat.getIsParent()?"closed":"open");
            result.add(node);
        }
        return result;
    }
}
